package com.ilovepostcard.view;

import com.ilovepostcard.R;
import com.ilovepostcard.model.Order;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class OrderRow extends LinearLayout {
    
    private TextView order_number;
    
    private TextView order_time;
    
    private ImageView order_status;
    
    private TextView order_text_status;

    public OrderRow(Context context, AttributeSet attrs) {
        super(context, attrs);
        inflate();
    }

    public OrderRow(Context context) {
        super(context);
        inflate();
    }
    
    public void setOrder(Order order) {
        order_number.setText("订单号：" + order.OrderID);
        order_time.setText("订单生成时间：" + order.OrderTime);
        /*if (Order.STATUS_FINISHED == order.OrderStatus) {
            order_status.setVisibility(VISIBLE);
            order_text_status.setVisibility(GONE);
        } else */{
            order_status.setVisibility(GONE);
            order_text_status.setText(order.getStatusText());
            order_text_status.setVisibility(VISIBLE);
            order_text_status.setTextColor(order.OrderStatus ==1 ? Color.RED : Color.BLACK);
        }
    }

    private void inflate() {
        View view = View.inflate(getContext(), R.layout.order_row, this);
        order_number = (TextView) view.findViewById(R.id.order_number);
        order_time = (TextView) view.findViewById(R.id.order_time);
        order_status = (ImageView) view.findViewById(R.id.order_status);
        order_text_status = (TextView) view.findViewById(R.id.order_text_status);
    }
}
